package sliding_window;

public class longestOnes {
    public int longestOnes(int[] nums, int k) {
        int[] hash = new int[2];
        int left = 0;
        int right = 0;
        int max = 0;
        //进入窗口
        while(right < nums.length) {

            hash[nums[right]]++;
            while(hash[0] > k) {//出窗口
                hash[nums[left]]--;
                left++;
            }
            max = Math.max(right-left+1,max);
            right++;

        }
        return max;
    }
}
